<!-- 排班设置页 -->
<template>
  <div class="dashboard-container waybill-list customer-list-box">
    <div class="el-main">
      <el-button
        class="add-work"
        type="primary"
        @click="addValueUser"
      >添加工作模式</el-button>
      <el-table
        :data="items"
        stripe
        style="width: 100%"
      >
        <el-table-column
          prop="id"
          label="工作模式编号"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="工作模式"
          width="180"
        >
        </el-table-column>
        <el-table-column
          prop="workPatternTypeDesc"
          label="类型"
        >
        </el-table-column>
        <el-table-column
          prop="workDate"
          label="工作日期"
        >
        </el-table-column>
        <el-table-column
          prop="workStartMinute1]"
          label="工作时间"
        >
        </el-table-column>
        <el-table-column
          label="操作"
        >
          <template v-slot="{ row }">
            <el-button
              type="text"
              @click="updataPermission(row.id)"
            >编辑</el-button>
            <el-button
              type="text"
              @click="open(row.id)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="userInfo.page"
        :page-size="userInfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
    <!-- 修改 -->
    <el-dialog
      :visible.sync="dialogFormVisible"
    >
      <el-form
        :model="userInfoList"
        label-width="120px"
      >
        <el-form-item
          label="工作模式名称"
          prop="name"
        >
          <el-input
            v-model="userInfoList.name"
            style="width:90%"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="连续工作天数："
          prop="workDayNum"
        >
          <el-checkbox checked="true">周一</el-checkbox>
          <el-checkbox label="周二"></el-checkbox>
          <el-checkbox label="周三"></el-checkbox>
          <el-checkbox label="周四"></el-checkbox>
          <el-checkbox label="周五"></el-checkbox>
          <el-checkbox label="周六"></el-checkbox>
          <el-checkbox label="周日"></el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-time-pricker></el-time-pricker>
          <el-time-pricker></el-time-pricker>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 添加 -->
    <el-dialog
      title="新增工作模式"
      :visible.sync="dialogFormVisiblesr"
    >
      <div class="addbox">
        <el-button
          type="text"
          style="font-size: 16px; color: #20232a;"
          @click="libai"
        >
          礼拜制
        </el-button>
        <el-button
          type="text"
          style="font-size: 16px;color: #20232a;"
          @click="lianxu"
        >
          连续制
        </el-button>
      </div>
      <el-form
        v-if="showForm"
        :model="addUserInfo"
        label-width="120px"
        style="padding: 30px"
      >
        <el-form-item
          label="工作模式名称"
          prop="name"
        >
          <el-input
            v-model="addUserInfo.name"
            style="width:78%"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="连续工作天数"
          prop="name"
        >
          <el-checkbox-group v-model="workday">
            <el-checkbox
              label="1"
            >周一</el-checkbox>
            <el-checkbox
              label="1"
            >周二</el-checkbox>
            <el-checkbox label="{wednesday: 1}">周三</el-checkbox>
            <el-checkbox label="{thursday: 1}">周四</el-checkbox>
            <el-checkbox label="{friday: 1}">周五</el-checkbox>
            <el-checkbox label="{saturday: 1}">周六</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item
          label="工作时间"
          style="width:82%"
        >
          <el-time-picker
            v-model="addUserInfo.workStartMinute1"
            is-range
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          ></el-time-picker>
        </el-form-item>
        <el-form-item>
          <el-row
            type="flex"
            justify="center"
          >
            <el-col>
              <el-button
                type="primary"
                @click="addWorkList"
              >确定</el-button>
            </el-col>
            <el-col>
              <el-button>取消</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </el-form>
      <el-form v-if="showFormxu">
        <el-form-item label="132">
          465
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { settingList, delUserList, updataList } from '@/api/workarrange'
export default {
  data() {
    return {
      userInfo: {
        page: 1,
        pageSize: 10
      },
      // 总条数
      total: 0,
      items: [],
      // 控制添加的类型
      showForm: true,
      showFormxu: false,
      // 接收添加的多选数据
      workday: [],
      // 添加数据收集
      addUserInfo: {
        friday: '',
        monday: '',
        name: '',
        operator: 0,
        restDayNum: 0,
        saturday: '',
        sunday: '',
        thursday: '',
        tuesday: '',
        userType: '',
        wednesday: '',
        workDayNum: 0,
        workEndMinute1: 0,
        workPatternType: '',
        workStartMinute1: 0
      },
      // 控制添加显示隐藏
      dialogFormVisiblesr: false,
      // 控制详情弹出框显示隐藏
      dialogFormVisible: false,
      // 详情数据
      userInfoList: {},
      // 详情回写多选
      works: []
    }
  },
  created() {
    this.settingList()
  },
  methods: {
    // 获取table数据
    async settingList() {
      const red = await settingList()
      this.items = red.data.items
      console.log(red.data)
      this.userInfo.page = red.data.items.page
      this.userInfo.pageSize = red.data.items.pageSize
      this.total = Number(red.data.counts)
    },
    // 分页
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    // 页数切换
    async handleCurrentChange(val) {
      this.userInfo.page = Number(val)
      const red = await settingList(this.userInfo)
      this.items = red.data.items
    },
    // 添加
    addValueUser() {
      this.dialogFormVisiblesr = true
    },
    // 礼拜制
    libai() {
      this.workPatternType = 0
      this.workPatternType = 1
      this.showForm = true
      this.showFormxu = false
    },
    // 连续制
    lianxu() {
      this.workPatternType = 0
      this.showFormxu = false
      this.workPatternType = 2
      this.showForm = false
    },
    // 添加
    addWorkList() {
      console.log(this.workday)
    },
    // 修改
    async updataPermission(row) {
      this.dialogFormVisible = true
      const red = await updataList(row)
      this.userInfoList = red.data
      console.log(this.userInfoList)
    },
    // 删除
    editPermission(row) {
      this.$nextTick(async () => {
        const del = await delUserList(row)
        this.$message.success(del.msg)
        this.settingList()
      })
    },
    open(row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.editPermission(row)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .table-card-box {
  .el-card__body {
    padding-bottom: 0px;
  }
}
::v-deep .pagination{
  padding-bottom: 30px;
}
.tab-box {
  color: #20232a;
  ::v-deep .el-tabs__item.is-active {
    color: #20232a;
    font-size: 16px;
    font-weight: bold;
  }
  ::v-deep .el-form-item__content {
    height: 40px;
  }
  ::v-deep .el-tabs__item {
    font-size: 14px;
  }
  ::v-deep .el-tabs__item:hover {
    color: #20232a;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
  }
  ::v-deep .el-tabs__active-bar {
    background-color: #e15536;
  }
  ::v-deep .tips {
    margin-left: 130px;
    margin-bottom: 14px;
    color: #bac0cd;
  }
  .el-checkbox {
    margin-right: 12px;
  }
  ::v-deep .workDay {
    .el-form-item__error {
      position: relative;
    }
  }
}
::v-deep .el-dialog__body {
  padding-top: 30px !important;
  .el-tabs__header {
    padding-bottom: 25px;
  }
}
::v-deep .el-tabs__nav,
.is-top {
  transform: translateX(30px) !important;
}
.el-table {
  margin: 30px 6px;
}
.customer-list-box {
  padding: 20px;
  background-color: #fff;
}
  .main-nei {
    width: 100%;
    color: #333;
    padding: 0px 20px;
    margin-top: 21px;
  }
.add-work {
margin-top: 5px;
margin-left: 7px;
}
.el-pagination {
  text-align: center;
}
.addbox {
  border: none;
  border-bottom: 1px solid red;
  width: 580px;
  position: absolute;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -50%);
}
.el-form {
  margin-top: 73px;
}
</style>
